import scrapy
from ..items import Spider04Item
import time

class Getdata04Spider(scrapy.Spider):
    name = "getdata04"
    custom_settings = {
        'ITEM_PIPELINES':{'spider04.pipelines.Spider04Pipeline': 100
    }
        }
    allowed_domains = ["movie.douban.com"]
    start_urls = ["https://movie.douban.com/cinema/nowplaying/shenzhen"]

    def parse(self, response):
        item = Spider04Item()
        movie_list = response.xpath('//*[@id="nowplaying"]/div[2]/ul/li/ul')
        count = 0
        # item = {}
        # item["name"] = "getdata04"
        # item["grade"] = "getdata04"
        # item = Spider04Item()
        # item['url'] = []
        for i in movie_list:
            # img_url = i.xpath('.//li/a/img/@src').extract_first()
            item['name'] = i.xpath('.//li[2]/a/@title').extract_first()
            item['grade'] = str(i.xpath('.//li[3]/span/text()').extract_first())
            # item['url'].append(img_url)
            count +=1
            time.sleep(0.1)
            print(item['name'],item['grade'])

            yield item
        print("一共有"+str(count)+"条")
        # print(item['url'])




